package com.struts2_2_3.converter;

import java.util.Map;
import java.util.StringTokenizer;

import ognl.DefaultTypeConverter;

import com.struts2_2_3.bean.User;

public class UserConverter extends DefaultTypeConverter {

	@SuppressWarnings("rawtypes")
	@Override
	public Object convertValue(Map context, Object value, Class toType) {

		if (User.class == toType) { // 从页面向后台对象转换

			String[] str = (String[]) value;

			String firstValue = str[0];

			StringTokenizer st = new StringTokenizer(firstValue, ";");

			String username = st.nextToken();

			String password = st.nextToken();

			User user = new User();

			user.setUsername(username);

			user.setPassword(password);

			return user;

		}

		return null;
	}
}
